package(default_visibility = ["//visibility:public"])

load(
    "//tools/vector_gen:vector_gen.bzl",
    "drake_cc_vector_gen_library",
    "vector_gen_lcm_sources",
)
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
)
load(
    "//tools/skylark:drake_py.bzl",
    "drake_py_binary",
    "drake_py_library",
)
load(
    "//tools/skylark:drake_lcm.bzl",
    "drake_lcm_cc_library",
)
load("//tools/lint:lint.bzl", "add_lint_tests")

drake_py_binary(
    name = "lcm_vector_gen",
    srcs = ["lcm_vector_gen.py"],
    deps = [
        "//tools/lint:find_data",
    ],
)

# === test/ ===

# From sample.named_vector, create gen/sample.{h,cc} (a BasicVector subclass).
drake_cc_vector_gen_library(
    name = "sample",
    testonly = 1,
    srcs = ["test/sample_named_vector.yaml"],
)

# From sample.named_vector, create lcmt_sample_t.lcm (message definition).
vector_gen_lcm_sources(
    name = "sample_lcm_srcs",
    testonly = 1,
    srcs = ["test/sample_named_vector.yaml"],
)

# From lcmt_sample_t.lcm, create lcmt_sample_t.hpp (C++ bindings).
drake_lcm_cc_library(
    name = "sample_lcmtypes_cc",
    testonly = 1,
    includes = ["test"],
    lcm_package = "drake",
    lcm_srcs = ["test/lcmt_sample_t.lcm"],
    strip_include_prefix = "/tools/vector_gen/test",
)

drake_cc_googletest(
    name = "sample_test",
    deps = [
        ":sample",
        "//common:default_scalars",
        "//common/test_utilities",
        "//common/yaml",
    ],
)

sh_test(
    name = "lcm_vector_gen_test",
    size = "small",
    srcs = ["test/lcm_vector_gen_test.sh"],
    data = [
        "test/gen/sample.cc",
        "test/gen/sample.h",
        "test/goal/lcmt_sample_t.lcm",
        "test/goal/sample.cc",
        "test/goal/sample.h",
        "test/lcmt_sample_t.lcm",
    ],
    # Valgrind Memcheck reports several leaks in the sed executable.
    tags = ["no_memcheck"],
)

add_lint_tests()
